package com.xh.cdp.sys.controller;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xh.cdp.common.BaseController;
import com.xh.cdp.common.EasyUIPageModel;
import com.xh.cdp.sys.entity.SysRoleEntity;
import com.xh.cdp.sys.service.SysRoleService;

@Controller
@RequestMapping("/sys/role")
public class RoleController extends BaseController {

	private static Logger log = LogManager.getLogger(RoleController.class);

	@Autowired
	private SysRoleService sysRoleService;

	@RequestMapping("/listRole")
	@ResponseBody
	public EasyUIPageModel<SysRoleEntity> listRole(String sort, String order, int page, int rows) {
		return sysRoleService.listRole(sort, order, page, rows);
	} 
	
	@RequestMapping("/addRole")
	@ResponseBody
	public String addRole(SysRoleEntity role, String rolePower) {
		return sysRoleService.addRole(role, rolePower);
	} 
	
	@RequestMapping("/updateRole")
	@ResponseBody
	public String updateRole(SysRoleEntity role, String rolePower) {
		return sysRoleService.updateRole(role, rolePower);
	}
	
	@RequestMapping("/showRoleInfo")
	@ResponseBody
	public SysRoleEntity showRoleInfo(String id) {
		return sysRoleService.showRoleInfo(id);
	}
	
	@RequestMapping("/updateRoleState")
	@ResponseBody
	public Integer updateRoleState(SysRoleEntity role) {
		return sysRoleService.updateRoleState(role);
	}
	
	@RequestMapping("/deleteRole")
	@ResponseBody
	public String deleteRole(String ids) {
		Integer row = sysRoleService.deleteRole(ids);
		if(row > 0) {
			return "success";
		}
		return "";
	}
	
	@RequestMapping("/searchByCondition")
	@ResponseBody
	public EasyUIPageModel<SysRoleEntity> searchByCondition(String sort, String order, Integer page, Integer rows, String searchName, Integer state) {
		return sysRoleService.listRoleBySearch(sort, order, page, rows, searchName, state);
	}
	
	/**
	 * 用户管理界面的角色选择下拉框
	 * @return
	 */
	@RequestMapping("/listUserRoleCombobox/{cate}")
	@ResponseBody
	public List<SysRoleEntity> listUserRoleCombobox(@PathVariable String cate) {
		System.out.println("cate:" + cate);
		return sysRoleService.listUserRoleCombobox(cate);
	}
}
